package com.ruoyi.queue.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.queue.domain.QueBiz;
import com.ruoyi.queue.service.IQueBizService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 排队业务Controller
 *
 * @author Zliming
 * @date 2020-03-15
 */
@Controller
@RequestMapping("/queue/biz")
public class QueBizController extends BaseController {
    private String prefix = "queue/biz";

    @Autowired
    private IQueBizService queBizService;

    @RequiresPermissions("queue:biz:view")
    @GetMapping()
    public String biz() {
        return prefix + "/biz";
    }

    /**
     * 查询排队业务列表
     */
    @RequiresPermissions("queue:biz:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QueBiz queBiz) {
        startPage();
        List<QueBiz> list = queBizService.selectQueBizList(queBiz);
        return getDataTable(list);
    }

    /**
     * 导出排队业务列表
     */
    @RequiresPermissions("queue:biz:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QueBiz queBiz) {
        List<QueBiz> list = queBizService.selectQueBizList(queBiz);
        ExcelUtil<QueBiz> util = new ExcelUtil<QueBiz>(QueBiz.class);
        return util.exportExcel(list, "biz");
    }

    /**
     * 新增排队业务
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存排队业务
     */
    @RequiresPermissions("queue:biz:add")
    @Log(title = "排队业务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QueBiz queBiz) {
        return toAjax(queBizService.insertQueBiz(queBiz));
    }

    /**
     * 修改排队业务
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        QueBiz queBiz = queBizService.selectQueBizById(id);
        mmap.put("queBiz", queBiz);
        return prefix + "/edit";
    }

    /**
     * 修改保存排队业务
     */
    @RequiresPermissions("queue:biz:edit")
    @Log(title = "排队业务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QueBiz queBiz) {
        return toAjax(queBizService.updateQueBiz(queBiz));
    }

    /**
     * 删除排队业务
     */
    @RequiresPermissions("queue:biz:remove")
    @Log(title = "排队业务", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(queBizService.deleteQueBizByIds(ids));
    }
}
